home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.sprintlink.net!eskimo!scs
- From: scs@eskimo.com (Steve Summit)
- Subject: Re: system() & error detection
- X-Nntp-Posting-Host: eskimo.com
- Message-ID: <DnnwIw.AGA@eskimo.com>
- Sender: news@eskimo.com (News User Id)
- Organization: schmorganization
- References: <4gt24g$dba@ncar.ucar.edu> <313728B7.2112A121@eiffel.com>
- Date: Sat, 2 Mar 1996 22:44:56 GMT
-
- In article <313728B7.2112A121@eiffel.com>, "Guus Leeuw jr."
- <guusl@eiffel.com> writes:
- > James Adams wrote:
- >> I am attempting to use the system() call in order to have a
- >> user-specified command execute in my program.
- >> I am wondering how I can check whether or not the command has
- >> completed successfully ? ... I'd like to be
- >> able to do something like the following:
- >> result = system(command);
- >> if (result == ERROR)
- >> exit(0);
- >>
- >> Is there anyway to do this ? Should I be using something other than
- >> system() ?
- >
- > According to the standard (references are listed with FAQ 19.27),
- > system() will return -1 upon execution error. Any other value is the
- > return code of the called program.
-
- Er, not quite. The only thing the ANSI/ISO C standard specifies
- is that if you call system((char *)NULL), you'll get a nonzero
- result "only if a command processor is available." As someone
- (probably Lawrence Kirby) was just reminding me, the return value
- when you pass system() an actual command string is implementation-
- defined.
-
- Certainly, a high-quality implementation will arrange that
- system() returns the exit status of the executed command,
- as that's what many calling programs need (and expect).
- I suspect that James Adams is using MS-DOS, since what he asks
- for (as if it didn't work for him) is exactly what quality
- system() implementations already offer. Under MS-DOS, however,
- system() does *not* return the exit status of the invoked
- command, and it turns out that it's not even the C library's
- fault, but rather COMMAND.COM's. (There's a remote chance that
- this has been fixed by now; I last tested it under MS-DOS version
- 6.00.) If you're stuck with MS-DOS, and the command you're
- invoking is a regular executable and not something built in to
- COMMAND.COM, you can get an accurate exit status by calling one
- of the spawn() routines instead of system().
-
- Steve Summit
- scs@eskimo.com
- --
- The Communications Decency Act within the Telecommunications Act
- of 1996 (U.S.) is an annoying, threatening, abusive, indecent,
- and obscene piece of legislation which attempts to ban annoying,
- threatening, abusive, indecent, or obscene communication.
-